namespace TSL.Utility.Json
{
    using System;
    using System.Text;

    public class GuidConverter : IJavaScriptConverter
    {
        public GuidConverter()
        {
            base.m_serializableTypes = new Type[] { typeof(Guid) };
            base.m_deserializableTypes = base.m_serializableTypes;
        }

        public override object Deserialize(IJavaScriptObject o, Type t)
        {
            return new Guid(o.ToString());
        }

        public override string Serialize(object o)
        {
            StringBuilder sb = new StringBuilder();
            this.Serialize(o, sb);
            return sb.ToString();
        }

        public override void Serialize(object o, StringBuilder sb)
        {
            JavaScriptUtil.QuoteString(o.ToString(), sb);
        }
    }
}

